# 构建镜像: docker build -t xbear/PHP_IMAGE .
FROM PHP_IMAGE

# 切换阿里源
COPY sources.list /etc/apt/sources.list

# 安装扩展
# 系统扩展: apt-get install 
# PHP 自带扩展: docker-php-ext-install
# pecl 安装扩展: pecl install 扩展名，安装后需要 docker-php-ext-enable 开启
RUN apt-get update \
  # gd
  && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
  && docker-php-ext-configure gd --with-freetype --with-jpeg \
  && docker-php-ext-install -j$(nproc) gd \
  # zip
  && apt-get install -y zlib1g-dev libzip-dev \
  && docker-php-ext-install zip \
  # composer
  && curl -sS https://getcomposer.org/installer | php \
  && mv composer.phar /usr/local/bin/composer \
  && chmod -R 777 /usr/local/bin/composer \
  && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ \
  # mysql pdo
  && docker-php-ext-install pdo pdo_mysql \
  # redis
  && pecl install redis \
  # swoole 需要指定版本，最新版需要 php>8 @see https://pecl.php.net/package/swoole
  && pecl install https://pecl.php.net/get/swoole-4.8.13.tgz \
  # 启用扩展
  && docker-php-ext-enable redis swoole \
  # 删除临时文件
  && rm -rf /tmp/pear \
  # 加载配置文件
  && mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
  